/*
 * @Date: 2023-12-18 17:55:55
 * @LastEditors: 玄绮 shijiahansi@qq.com
 * @LastEditTime: 2024-04-14 17:56:43
 * @FilePath: \serverd:\dev-code\vscode\boost_chat\client\src\forms\mainwindow\listforms\chatlistform.h
 */
#ifndef CHATLISTFORM_H
#define CHATLISTFORM_H

#include <QListWidgetItem>
#include <QWidget>
#include <data/UserInfo.pb.h>
using namespace proto;
#include <items/chatitem.h>
#include <talkwindow/talkwindow.h>
#include <map>
#include <memory>
// #include <packet/message/Message.h>
#include <queue>
#include <set>

class WindowManager;
namespace Ui {
    class ChatListForm;
}

class ChatListForm : public QWidget {
    Q_OBJECT

public:
    explicit ChatListForm(WindowManager* manager, QWidget* parent = nullptr);
    ~ChatListForm();

public:
    void onSetCurrent();

protected:
    void init();

public:
    void onMessage(std::shared_ptr<::proto::data::Message> msg);
    void onMessagePTOP(std::shared_ptr<::proto::data::Message> msg);
    void onMessageGROUP(std::shared_ptr<::proto::data::Message> msg);
    void onGetUserInfo(data::UserInfo userInfo, int code, QString message);
    void onGetRoomInfo(data::ChatRoomInfo roomInfo, int code, QString message);
    void addNewChat(const data::FriendInfo& userInfo);
    void addNewChat(const data::ChatRoomInfo& roomInfo);

signals:
    void signalAddSubWindow(QString windowName, QWidget* subWindow);
    void signalSetCurrentWidget(QString windowName);
    void signalSetCurrentWidget(QWidget* subWindow);

    void addNewItem(QString, QListWidgetItem* item);
    void signalToggle();

protected slots:
    void onItemClicked(QListWidgetItem* item);
    void onItemDoubleClicked(QListWidgetItem* item);
    void onTalkNewMessage(std::shared_ptr<::proto::data::Message> msg);

private:
    Ui::ChatListForm*                                                        ui;
    std::map<QString, QListWidgetItem*>                                      items;
    std::map<QString, ChatItem*>                                             chatItems;
    std::map<QString, TalkWindow*>                                           talkWindows;
    std::map<QString, std::queue<std::shared_ptr<::proto::data::Message>>> dendingMessages;
    WindowManager&                                                           windowManager;
};

#endif  // CHATLISTFORM_H
